#define _GNU_SOURCE
#include <stdarg.h>
#include <unistd.h>
#include <sched.h>
#include "pthread_impl.h"
#include "syscall.h"
#include <unsupported_api.h>

int clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
{
	va_list ap;
	pid_t *ptid, *ctid;
	void  *tls;
	int ret = -1;

	if (flags & CLONE_VFORK)
	{
		void* spawn_para = arg;
		ret = __syscall_ret(__clone(func, stack, flags, spawn_para, 0, 0, 0));
	} else {
		va_start(ap, arg);
		ptid = va_arg(ap, pid_t *);
		tls  = va_arg(ap, void *);
		ctid = va_arg(ap, pid_t *);
		va_end(ap);

		ret = __syscall_ret(__clone(func, stack, flags, arg, ptid, tls, ctid));
	}

	return ret;
}
